package com.ruoyi.project.product.size.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.product.size.domain.Size;
import com.ruoyi.project.product.size.mapper.SizeMapper;
import com.ruoyi.project.product.size.service.SizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: 高柯
 * @Date: 2020/4/15
 * @Description: com.ruoyi.project.product.size.service
 * @version: 2.0
 */
@Service
public class SizeServiceImpl implements SizeService {

    @Autowired
    private SizeMapper sizeMapper;

    @Override
    public List<Size> selectSizeList(Size size) {
        return sizeMapper.selectSizeList(size);
    }

    @Override
    public String checkSizeNameUnique(Size size) {
        Long sizeId = StringUtils.isNull(size.getSizeId()) ? -1L : size.getSizeId();
        Size info = sizeMapper.checkSizeNameUnique(size.getSizeName());
        if (StringUtils.isNotNull(info) && info.getSizeId().longValue() != sizeId.longValue())
        {
            return UserConstants.SERIES_NAME_NOT_UNIQUE;
        }
        return UserConstants.SERIES_NAME_UNIQUE;
    }

    @Override
    public int insertSize(Size size) {
        size.setCreateBy(ShiroUtils.getLoginName());
        return sizeMapper.insertSize(size);
    }

    @Override
    public Size selectSizeById(Long sizeId) {
        return sizeMapper.selectSizeById(sizeId);
    }

    @Override
    public int updateSize(Size size) {
        return sizeMapper.updateSize(size);
    }

    @Override
    public int deleteSizeByIds(String ids) {
        Long[] sizeIds = Convert.toLongArray(ids);
        //应该在删除之前先校验该类型下是否有公告，有则不能删除，报错

        return sizeMapper.deleteSizeByIds(sizeIds);
    }
}
